package com.liangtian.mdm.dm.jsp.common;

import com.liangtian.mdm.base.filter.CameHumpInterceptor;
import com.liangtian.mdm.dm.common.enums.Type;
import org.apache.commons.lang3.StringUtils;
import com.liangtian.mdm.dm.config.model.AttrConfig;
import com.liangtian.mdm.dm.model.model.Model;

import java.util.List;

public class ListJspCreate {


    public static String spellDisSearchJsp(List<AttrConfig> jspAttrLst, Model model) {
        StringBuilder sb = new StringBuilder();
        for (AttrConfig ac : jspAttrLst) {
            sb.append("<th data-field='").append(ac.getAttrColumn().toLowerCase()).append("' ")
                    .append(" data-sortable='true' ");
            String attrType = ac.getAttrType();
            if (("selectList").equals(attrType) || ("radioType").equals(attrType)
                    || ("checkBoxType").equals(attrType) || ("popList").equals(attrType) || ("listTree").equals(attrType)) {
                sb.append("data-filter-control='select'");
            } else {
                sb.append("data-filter-control='input' width='20%'");
            }
            sb.append(">").append(ac.getAttrName());
            sb.append("</th> \r\n");
        }
        return sb.toString();
    }

    /**
     * 拼写查询页面
     *
     * @param jspAttrLst <th data-field='attrName'>属性名称</th>
     * @return data-filter-control="input"
     */
    public static String spellSearchJsp(List<AttrConfig> jspAttrLst, Model model) {
        StringBuilder sb = new StringBuilder();
        for (AttrConfig ac : jspAttrLst) {
            sb.append("    <shiro:hasPermission name='" + model.getTableName() + ":" + ac.getAttrColumn().toLowerCase() + "'>");
            sb.append("<th data-field='").append(ac.getAttrColumn().toLowerCase()).append("' ");//.append(" data-sortable='true' ")
            String attrType = ac.getAttrType();
            if (("selectList").equals(attrType) || ("radioType").equals(attrType)
                    || ("checkBoxType").equals(attrType) || ("popList").equals(attrType) || ("listTree").equals(attrType)) {
                sb.append("data-filter-control='select'");
            } else {
                sb.append("data-filter-control='input' width='20%'");
            }
            sb.append(">").append(ac.getAttrName());
            sb.append("</th></shiro:hasPermission> \r\n");
        }
        if (model.getModelType().equals("0")) {
            if (model.getIsSubtable() != 1) {//标识是不是从表，如果不是从表，及意味着是主表
                sb.append("<th data-formatter=" + "viewDetailFormat" + ">查看详情</th> \r\n");
                sb.append("<th data-formatter=" + "viewHisApproveFormat" + ">审批意见</th> \r\n");

            }
        }
        return sb.toString();
    }

    /**
     * 拼写POP弹出页面
     *
     * @param jspAttrLst <th data-field='attrName'>属性名称</th>
     * @return data-filter-control="input"
     */
    public static String spellPopJsp(List<AttrConfig> jspAttrLst, Model model) {
        StringBuilder sb = new StringBuilder();
        for (AttrConfig ac : jspAttrLst) {
            sb.append("                <shiro:hasPermission name='" + model.getTableName() + ":" + ac.getAttrColumn().toLowerCase() + "'>");
            sb.append("<th data-field='").append(ac.getAttrColumn().toLowerCase()).append("' ")
            ;
            String attrType = ac.getAttrType();
            if (("selectList").equals(attrType) || ("radioType").equals(attrType) || ("checkBoxType").equals(attrType)
                    || ("popList").equals(attrType) || ("listTree").equals(attrType)) {
                sb.append("data-filter-control='select'");
            } else {
                sb.append("data-filter-control='input' width='20%'");
            }
            sb.append(">").append(ac.getAttrName());
            sb.append("</th></shiro:hasPermission> \r\n");
        }
        return sb.toString();
    }

    //生成弹出列表，非动态模型相关表的数据操作
    public static String spellPopNoTabJsp(String confColumn, Model model) {
        StringBuilder sb = new StringBuilder();
        String column[] = confColumn.split(",");
        for (int i = 0; i < column.length; i++) {
            String col = column[i];
            col = CameHumpInterceptor.underlineToCamelhump(col);
            //在这里引用一个方法，将带有下划线的字段
            sb.append("<th data-field='").append(col).append("' ")
                    .append(" data-sortable='true' ");
            sb.append("data-filter-control='input' width='20%'");
            sb.append(">").append("数据来源");
            sb.append("</th>\r\n");
        }
        return sb.toString();
    }

    /**
     * 拼写申请
     *
     * @param jspAttrLst
     * @return
     */
    public static String spellAddOrEditJsp(List<AttrConfig> jspAttrLst, Model model) {
        StringBuilder sb = new StringBuilder();
        if (model.getIsMoreView() == 1) {//表示是多视图模型
            for (AttrConfig ac : jspAttrLst) {
                sb.append("<th data-field='").append(ac.getAttrColumn().toLowerCase()).append("' ").append(">");
                sb.append(ac.getAttrName());
                sb.append("</th>\r\n");
            }
        } else {
            for (AttrConfig ac : jspAttrLst) {
                sb.append("            <shiro:hasPermission name='" + model.getTableName() + ":" + ac.getAttrColumn().toLowerCase() + "'>");
                sb.append("<th data-field='").append(ac.getAttrColumn().toLowerCase()).append("' ").append(">");
                sb.append(ac.getAttrName());
                sb.append("</th></shiro:hasPermission> \r\n");
            }
        }

        if (model.getModelType().equals("0")) {
            if (model.getIsSubtable() != 1) {//标识是不是从表，如果不是从表，及意味着是主表
                sb.append("<th data-formatter=" + "viewDetailFormat" + ">查看详情</th> \r\n");
                sb.append("<th data-formatter=" + "viewHisApproveFormat" + ">审批意见</th> \r\n");

            }
        }
        return sb.toString();
    }

    //详情页面
    public static String spellApplyJspDetail(List<AttrConfig> jspAttrLst, Model model) {
        StringBuilder sb = new StringBuilder();
        for (AttrConfig ac : jspAttrLst) {
            sb.append("          <shiro:hasPermission name='" + model.getTableName() + ":" + ac.getAttrColumn().toLowerCase() + "'>");
            sb.append("<th data-field='").append(ac.getAttrColumn().toLowerCase()).append("'>");
            sb.append(ac.getAttrName());
            sb.append("</th></shiro:hasPermission> \r\n");
        }
        return sb.toString();
    }

    /**
     * 将拼接好的字符串内容替换掉自动生成的模板的内容
     *
     * @param formatJspStr
     * @param readFilePath
     */
    public static void createListPage(Model model, String formatJspStr, String readFilePath, String operType) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String html = jspTmpContent.replace("{tableTd}", formatJspStr)
                    .replace("{updateButtonLst}", spellButton(model, operType));
            if ("update".equals(operType) || "treeTabUpdate".equals(operType)) {
                if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId()))
                    html = html.replace("{mainIdInput}", "<input type='hidden' id='mainId' value='<%= request.getParameter(\"mainId\")%>'>");
                else
                    html = html.replace("{mainIdInput}", "");
            }
            html = JspUtil.replaceTreeFormat(html, model, operType); // 格式化换行等占位符
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 将拼接好的字符串内容替换掉自动生成的模板的内容
     */
    public static void createListDetailPage(Model model, String formatJspStr, String readFilePath, String surveyType, String operType) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String html = jspTmpContent.replace("{tableTd}", formatJspStr); // 将占位符替换成拼接的内容
            html = JspUtil.replaceListDetailFormat(model, html, surveyType, operType); // 格式化换行等占位符
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * <p>TODO 申请页面生成方法（列表，多视图列表）</p>
     * <p>@param model
     * <p>@param formatJspStr
     * <p>@param readFilePath
     * <p>@param operType </p>
     *
     * @author : xiaoliu
     * @date :2017年7月8日上午8:04:44
     */
    public static void createApplyPage(Model model, String formatJspStr, String readFilePath, String operType) {
        try {
            String html = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            html = html.replace("{applyButtonLst}", spellButton(model, operType))
                    .replace("{tableTd}", formatJspStr)
                    .replace("{modelId}", model.getId());
            //判断是不是列表，且是不是从表
            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {
                html = html.replace("{mainIdInput}", " <input type='hidden' id='mainId' value='<%= request.getParameter(\"mainId\")%>'>");
            } else {
                html = html.replace("{mainIdInput}", "");
            }
            html = JspUtil.replaceListFormat(html, model, operType); // 格式化换行等占位符
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    //写一个方法，概括所有按钮==拼写所有按钮，动态的生成在页面上
    public static String spellButton(Model model, String operType) {
        StringBuilder sb = new StringBuilder();
        if ("apply".equals(operType) || "treeTabApply".equals(operType)) {//如果是申请页面
            sb.append("          <shiro:hasPermission name='" + model.getTableName() + ":add'> $RN$");
            sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
            sb.append("                   <i class='glyphicon glyphicon-plus' aria-hidden='true'></i>新增 $RN$");
            sb.append("               </button> $RN$");
            sb.append("          </shiro:hasPermission> $RN$");
            sb.append("          <shiro:hasPermission name='" + model.getTableName() + ":edit'> $RN$");
            sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
            sb.append("                   <i class='glyphicon glyphicon-edit' aria-hidden='true'></i>编辑 $RN$");
            sb.append("               </button> $RN$");
            sb.append("          </shiro:hasPermission> $RN$");
            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {//字典类型，从表

            } else {
                sb.append("      <shiro:hasPermission name='" + model.getTableName() + ":submit'> $RN$");
                sb.append("          <button type='button' class='btn btn-outline btn-default'> $RN$");
                sb.append("               <i class='glyphicon glyphicon-arrow-up' aria-hidden='true'></i>提交 $RN$");
                sb.append("          </button> $RN$");
                sb.append("      </shiro:hasPermission> $RN$");
            }
            sb.append("          <shiro:hasPermission name='" + model.getTableName() + ":del'> $RN$");
            sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
            sb.append("                    <i class='glyphicon glyphicon-trash' aria-hidden='true'></i>删除$RN$");
            sb.append("               </button> $RN$");
            sb.append("          </shiro:hasPermission> $RN$");
            sb.append("          <shiro:hasPermission name='" + model.getTableName() + ":exportTmp'> $RN$");
            sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
            sb.append("                   <i class='glyphicon glyphicon-book' aria-hidden='true'></i>导出模板 $RN$");
            sb.append("               </button> $RN$");
            sb.append("          </shiro:hasPermission> $RN$");
            sb.append("          <shiro:hasPermission name='" + model.getTableName() + ":impExcel'> $RN$");
            sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
            sb.append("                     <i class='glyphicon glyphicon-open' aria-hidden='true'></i>导入 $RN$");
            sb.append("               </button> $RN$");
            sb.append("          </shiro:hasPermission> $RN$");
        } else if ("update".equals(operType) || "treeTabUpdate".equals(operType)) {//如果是变更页面

            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {//字典类型，从表
                sb.append("            <button type='button' class='btn btn-outline btn-default'> $RN$");
                sb.append("               <i class='glyphicon glyphicon-plus' aria-hidden='true'></i>新增 $RN$");
                sb.append("            </button> $RN$");
            } else {
                sb.append("       <shiro:hasPermission name='" + model.getTableName() + ":updateSubmit'> $RN$");
                sb.append("            <button type='button' class='btn btn-outline btn-default'> $RN$");
                sb.append("                <i class='glyphicon glyphicon-arrow-up' aria-hidden='true'></i>提交 $RN$");
                sb.append("            </button> $RN$");
                sb.append("       </shiro:hasPermission> $RN$");

                sb.append("       <shiro:hasPermission name='" + model.getTableName() + ":selUpdateData'> $RN$");
                sb.append("            <button type='button' class='btn btn-outline btn-default'> $RN$");
                sb.append("                 <i class='glyphicon glyphicon-plus' aria-hidden='true'></i>选择修改 $RN$");
                sb.append("            </button> $RN$");
                sb.append("       </shiro:hasPermission> $RN$");
            }
            sb.append("           <shiro:hasPermission name='" + model.getTableName() + ":selStartData'> $RN$");
            sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
            sb.append("                   <i class='glyphicon glyphicon-ok' aria-hidden='true'></i>选择解冻 $RN$");
            sb.append("               </button> $RN$");
            sb.append("           </shiro:hasPermission> $RN$");
            sb.append("           <shiro:hasPermission name='" + model.getTableName() + ":selStopData'> $RN$");
            sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
            sb.append("                   <i class='glyphicon glyphicon-remove' aria-hidden='true'></i>选择冻结 $RN$");
            sb.append("               </button> $RN$");
            sb.append("           </shiro:hasPermission> $RN$");
            sb.append("           <shiro:hasPermission name='" + model.getTableName() + ":updateEdit'> $RN$");
            sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
            sb.append("                   <i class='glyphicon glyphicon-edit' aria-hidden='true'></i>编辑 $RN$");
            sb.append("               </button> $RN$");
            sb.append("           </shiro:hasPermission> $RN$");
            sb.append("           <shiro:hasPermission name='" + model.getTableName() + ":updateDel'> $RN$");
            sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
            sb.append("                   <i class='glyphicon glyphicon-trash' aria-hidden='true'></i>取消 $RN$");
            sb.append("               </button> $RN$");
            sb.append("           </shiro:hasPermission> $RN$");
        }

        return sb.toString().replace("$RN$", "\r\n");
    }


//	public static String spellApplyButton(Model model){
//		StringBuilder sb=new StringBuilder();
//		sb.append("          <shiro:hasPermission name='"+model.getTableName()+":add'> $RN$");
//		sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
//		sb.append("                   <i class='glyphicon glyphicon-plus' aria-hidden='true'></i>新增 $RN$");
//		sb.append("               </button> $RN$");
//		sb.append("          </shiro:hasPermission> $RN$");
//		sb.append("          <shiro:hasPermission name='"+model.getTableName()+":edit'> $RN$");
//		sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
//		sb.append("                   <i class='glyphicon glyphicon-edit' aria-hidden='true'></i>编辑 $RN$");
//		sb.append("               </button> $RN$");
//		sb.append("          </shiro:hasPermission> $RN$");
//		if("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())){//字典类型，从表
//			
//		}else{
//			sb.append("      <shiro:hasPermission name='"+model.getTableName()+":submit'> $RN$");
//			sb.append("          <button type='button' class='btn btn-outline btn-default'> $RN$");
//			sb.append("               <i class='glyphicon glyphicon-arrow-up' aria-hidden='true'></i>提交 $RN$");
//			sb.append("          </button> $RN$");
//			sb.append("      </shiro:hasPermission> $RN$");
//		}
//		sb.append("          <shiro:hasPermission name='"+model.getTableName()+":del'> $RN$");
//		sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
//		sb.append("                    <i class='glyphicon glyphicon-trash' aria-hidden='true'></i>删除 $RN$");
//		sb.append("               </button> $RN$");
//		sb.append("          </shiro:hasPermission> $RN$");
//		sb.append("          <shiro:hasPermission name='"+model.getTableName()+":exportTmp'> $RN$");
//		sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
//		sb.append("                   <i class='glyphicon glyphicon-book' aria-hidden='true'></i>导出模板 $RN$");
//		sb.append("               </button> $RN$");
//		sb.append("          </shiro:hasPermission> $RN$");
//		sb.append("          <shiro:hasPermission name='"+model.getTableName()+":impExcel'> $RN$");
//		sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
//		sb.append("                     <i class='glyphicon glyphicon-open' aria-hidden='true'></i>导入 $RN$");
//		sb.append("               </button> $RN$");
//		sb.append("          </shiro:hasPermission> $RN$");
//		return sb.toString().replace("$RN$", "\r\n");
//	}

//	public static String spellUpdataButton(Model model){
//		StringBuilder sb=new StringBuilder();
//		if("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())){//字典类型，从表
//			sb.append("            <button type='button' class='btn btn-outline btn-default'> $RN$");
//			sb.append("               <i class='glyphicon glyphicon-plus' aria-hidden='true'></i>新增 $RN$");
//			sb.append("            </button> $RN$");
//		}else{
//			sb.append("       <shiro:hasPermission name='"+model.getTableName()+":updateSubmit'> $RN$");
//			sb.append("            <button type='button' class='btn btn-outline btn-default'> $RN$");
//			sb.append("                <i class='glyphicon glyphicon-arrow-up' aria-hidden='true'></i>提交 $RN$");
//			sb.append("            </button> $RN$");
//			sb.append("       </shiro:hasPermission> $RN$");
//			
//			sb.append("       <shiro:hasPermission name='"+model.getTableName()+":selUpdateData'> $RN$");
//			sb.append("            <button type='button' class='btn btn-outline btn-default'> $RN$");
//			sb.append("                 <i class='glyphicon glyphicon-plus' aria-hidden='true'></i>选择修改数据 $RN$");
//			sb.append("            </button> $RN$");
//			sb.append("       </shiro:hasPermission> $RN$");
//		}
//		sb.append("           <shiro:hasPermission name='"+model.getTableName()+":selStartData'> $RN$");
//		sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
//		sb.append("                   <i class='glyphicon glyphicon-ok' aria-hidden='true'></i>数据解冻 $RN$");
//		sb.append("               </button> $RN$");
//		sb.append("           </shiro:hasPermission> $RN$");
//		sb.append("           <shiro:hasPermission name='"+model.getTableName()+":selStopData'> $RN$");
//		sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
//		sb.append("                   <i class='glyphicon glyphicon-remove' aria-hidden='true'></i>数据冻结 $RN$");
//		sb.append("               </button> $RN$");
//		sb.append("           </shiro:hasPermission> $RN$");
//		sb.append("           <shiro:hasPermission name='"+model.getTableName()+":updateEdit'> $RN$");
//		sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
//		sb.append("                   <i class='glyphicon glyphicon-edit' aria-hidden='true'></i>编辑 $RN$");
//		sb.append("               </button> $RN$");
//		sb.append("           </shiro:hasPermission> $RN$");
//		sb.append("           <shiro:hasPermission name='"+model.getTableName()+":updateDel'> $RN$");
//		sb.append("               <button type='button' class='btn btn-outline btn-default'> $RN$");
//		sb.append("                   <i class='glyphicon glyphicon-trash' aria-hidden='true'></i>删除 $RN$");
//		sb.append("               </button> $RN$");
//		sb.append("           </shiro:hasPermission> $RN$");
//		return sb.toString().replace("$RN$", "\r\n");
//	}
//	

    /**
     * 将拼接好的字符串内容替换掉自动生成的模板的内容
     *
     * @param formatJspStr
     * @param readFilePath
     */
    public static void createBatchImportPage(String readFilePath, Model model, String operType) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            // 将占位符替换成拼接的内容//T_1179/js/T_1179_batchImport.js
            String html = jspTmpContent.replace("{includeJs}", model.getTableName() + "/js/" + model.getTableName() + "_" + operType + ".js")
                    .replace("{modelId}", model.getId()).replace("@R#", "\r\n");
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 变更历史查询页面
     *
     * @param formatJspStr
     * @param readFilePath
     */
    public static void createUpdageHisPage(String formatJspStr, String readFilePath,
                                           Model model, String operType) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String html = jspTmpContent.replace("{tableTd}", formatJspStr); // 将占位符替换成拼接的内容
            html = JspUtil.replaceTreeFormat(html, model, operType); // 格式化换行等占位符
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * <p>Description: 生成树模板的main主页面 </p>
     * <p>@param readFilePath  对应的模板的‘treeTabMain’的jsp页面路径
     * <p>@param model ---生成页面的模型 model
     * <p>@param operType --  "treeTabMain" </p>
     *
     * @author : xiaoliu
     * @date :2016年12月14日上午9:27:59
     */
    public static void createTreeTabMainPage(String readFilePath, Model model, Model fenModel, String operType, List<AttrConfig> configLst) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String MainHtml = jspTmpContent.replace("{MainColumn}", JspUtil.spellColumn(model, Type.MAIN));
            MainHtml = JspUtil.replaceTreeTabMainFormat(MainHtml, model, fenModel, operType, configLst); // 格式化换行等占位符
            JspUtil.writeInJsp(MainHtml, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * <p>生成树模板的查询和申请页面</p>
     * <p>Company:@param formatJspStr
     * <p>Company:@param readFilePath
     * <p>Company:@param model
     * <p>Company:@param operType </p>
     *
     * @author : xiaoliu
     * @date :2016年12月14日上午10:21:45
     */
    public static void createTreeTabListPage(String formatJspStr, String readFilePath, Model model, String operType) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容

            jspTmpContent = jspTmpContent.replace("@R#", "\r\n");

            jspTmpContent = jspTmpContent.replace("{applyButtonLst}", spellButton(model, operType));
            String html = jspTmpContent.replace("{tableTd}", formatJspStr); // 将占位符替换成拼接的内容   String surveyType
            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId()))
                html = html.replace("{mainIdInput}", " <input type='hidden' id='mainId' value='<%= request.getParameter(\"mainId\")%>'>");
            else
                html = html.replace("{mainIdInput}", "");
            html = JspUtil.replaceTreeTabFormat(html, model, operType); // 格式化换行等占位符
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 将拼接好的字符串内容替换掉自动生成的模板的内容
     */
    public static void createPopListPage(String formatJspStr, String readFilePath,
                                         Model model, Model sourceModel, String popColum, String operType) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String html = jspTmpContent.replace("{tableTd}", formatJspStr); // 将占位符替换成拼接的内容
            html = html.replace("{bgPopColumn}", JspUtil.getBgPopColumn(model));
            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {
                html = html.replace("{mainIdInput}", " <input type='hidden' id='mainId' value='<%= request.getParameter(\"mainId\")%>'>");
            } else {
                html = html.replace("{mainIdInput}", "");
            }
            String sourceTableName = null;
            if (null != sourceModel && !"".equals(sourceModel)) {
                sourceTableName = sourceModel.getTableName();
            }
            html = JspUtil.replacePopFormat(html, model.getTableName(), sourceTableName, popColum, operType); // 格式化换行等占位符
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void createPopNoTabPage(String formatJspStr, String readFilePath,
                                          Model model, String tableName, String popColum, String operType) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String html = jspTmpContent.replace("{tableTd}", formatJspStr); // 将占位符替换成拼接的内容
            html = html.replace("{bgPopColumn}", JspUtil.getBgPopColumn(model));
            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {
                html = html.replace("{mainIdInput}", " <input type='hidden' id='mainId' value='<%= request.getParameter(\"mainId\")%>'>");
            } else {
                html = html.replace("{mainIdInput}", "");
            }
            html = JspUtil.replacePopFormat(html, model.getTableName(), tableName, popColum, operType); // 格式化换行等占位符
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void createTreeListPage(String formatJspStr, String readFilePath,
                                          Model model, String sourceSurveyType, String operType, String fileName) {
        // String surveyType = model.getTableName();
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String html = jspTmpContent.replace("{tableTd}", formatJspStr); // 将占位符替换成拼接的内容
            html = JspUtil.replaceTreeFormat(html, model, sourceSurveyType, operType, fileName); // 格式化换行等占位符
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}


    
